<template>
  <div class="main">
    <el-dialog title="工作成果审核" width="60%" :visible.sync="dialogFormVisible">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        class="demo-ruleForm"
      >
      <el-form-item label="执行描述" prop="workNotes">
          <el-input
            type="textarea"
            v-model="ruleForm.workNotes"
            maxlength="200"
            rows="3"
            readonly="readonly"
            show-word-limit
          ></el-input>
        </el-form-item>
      <el-form-item label="工作成果">
        <template>
        <el-table :data="ruleForm.workFiles" style="width: 100%">
            <el-table-column prop="fileName" label="文件名称">
            </el-table-column>
            <el-table-column prop="fileSize" label="文件大小（字节）">
            </el-table-column>
            <el-table-column label="操作" width="260" align="center">
            <template slot-scope="scope">
                <el-link :href="`${baseUrl}${scope.row.filePath}`" :underline="false" target="_blank">
                <span class="el-icon-document"> 下载文件 </span>
                </el-link>
            </template>
            </el-table-column>
        </el-table>
        </template>
      </el-form-item>
        <el-form-item label="审核意见" prop="processNotes">
          <el-input
            type="textarea"
            v-model="ruleForm.processNotes"
            maxlength="200"
            rows="3"
            show-word-limit
          ></el-input>
        </el-form-item>
        <!-- -->
        <!-- <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >立即创建</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeForm">取 消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >审核通过</el-button
        >
        <el-button type="secondary" @click="rejectForm('ruleForm')"
          >审核不通过</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { checkPass, checkReject } from "@/api/system/work";
export default {
  name: "addform",
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      dialogFormVisible: false,
      formLabelWidth: "120px",
      ruleForm: {},
      rules: {
      },
    };
  },
  created() {
  },
  methods: {
    showdate(value) {
      // console.log(value);
    },
    open() {
      this.dialogFormVisible = true;
    },
    closeForm() {
      this.resetForm("ruleForm");
      this.dialogFormVisible = false;
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          
          checkPass(this.ruleForm)
            .then(res => {
              // console.log(res);
              if (res.code == 200) {
                this.resetForm(formName);
                this.dialogFormVisible = false;
                this.$parent.init();
              }
            })
            .catch(error => {
              //  if (res.code == 500) {
              // this.ruleForm.manHour = this.ruleForm.temp;
              // this.$message.warning("工时还原为" + this.ruleForm.temp);
              // console.log("temphour", this.ruleForm.temp);
              // }
              // console.log(error);
            });
            
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    },
    rejectForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          
          checkReject(this.ruleForm)
            .then(res => {
              // console.log(res);
              if (res.code == 200) {
                this.resetForm(formName);
                this.dialogFormVisible = false;
                this.$parent.init();
              }
            })
            .catch(error => {
              //  if (res.code == 500) {
              // this.ruleForm.manHour = this.ruleForm.temp;
              // this.$message.warning("工时还原为" + this.ruleForm.temp);
              // console.log("temphour", this.ruleForm.temp);
              // }
              // console.log(error);
            });
            
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
};
</script>

<style scoped lang="scss">
.tip{
  font-size: 12px;
    color: #606266;
    margin-top: 7px;
}
</style>
